
class ConfigurationDialog

  @main

  def initialize(parent, main)

    @main = main

    @provider_combobox
    @input_login
    @input_password
    @input_own_number
    @label_helper

    SmsWidget::Main.logger.debug "configuration window activated ..."
     widget = Qt::Widget.new
     layout = Qt::GridLayout.new widget


      label_provider = Qt::Label.new widget
      label_provider.text = 'Provider'
      layout.addWidget label_provider, 0, 0

      @provider_combobox = Qt::ComboBox.new widget
      @provider_combobox.addItems(main.get_provider_names)
      provider_index_combo = @provider_combobox.findText(provider)
      @provider_combobox.setCurrentIndex(provider_index_combo)
      layout.addWidget @provider_combobox, 1, 0

      label_login = Qt::Label.new widget
      label_login.text = 'Login'
      layout.addWidget label_login, 2, 0

      @input_login = Qt::LineEdit.new widget
      @input_login.setText(main.login_name)
      @input_login.setEnabled(main.provider_list[provider]["login_needed"])
      layout.addWidget @input_login, 3, 0

      label_password = Qt::Label.new widget
      label_password.text = 'Password'
      layout.addWidget label_password, 2, 1

      @input_password = Qt::LineEdit.new widget
      @input_password.setText(main.password)
      @input_password.setEchoMode(Qt::LineEdit::Password)
      @input_password.setEnabled(main.provider_list[provider]["password_needed"])
      layout.addWidget @input_password, 3, 1

      label_own_number = Qt::Label.new widget
      label_own_number.text = 'Own Number'
      layout.addWidget label_own_number, 4, 0

      @input_own_number = Qt::LineEdit.new widget
      @input_own_number.setText(main.own_number)
      @input_own_number.setEnabled(main.provider_list[provider]["own_number_needed"])
      layout.addWidget @input_own_number, 5, 0

      @label_help = Qt::Label.new widget
      @label_help.setText(main.provider_list[provider]["help"])
      #@label_help.setFixedHeight(50)
      @label_help.setMinimumWidth(200)
      @label_help.setWordWrap(true)
      layout.addWidget @label_help, 2, 2, -1, 2


      @provider_combobox.connect(SIGNAL("currentIndexChanged(const QString&)")) do
        self.reload_config_gui()
      end

      parent.buttons = KDE::Dialog::Ok | KDE::Dialog::Cancel | KDE::Dialog::Apply
      

      parent.addPage(widget, KDE.i18n("Settings"))
    end

    def reload_config_gui()
      provider = @provider_combobox.currentText()
      provider_list = self.main.provider_list_yaml
      @input_login.setEnabled(provider_list[provider]["login_needed"])
      @input_password.setEnabled(provider_list[provider]["password_needed"])
      @input_own_number.setEnabled(provider_list[provider]["own_number_needed"])
      @label_help.setText(provider_list[provider]["help"])
    end

    def main()
      @main
    end

    def input_login()
      @input_login
    end

    def input_password()
      @input_password
    end

    def input_own_number()
      @input_own_number
    end

    def provider_combobox()
      @provider_combobox
    end

    def provider()
      main.provider
    end

    def provider_info(key)
      main.provider_list[provider][key]
    end

  end
